/**
 * @Copyright:Copyright (c) 1992 - 2015
 * @Company: TengTong
 */
package com.tengtong.duang.commons.convert;

/**
 *  源--转--目标匹配类
 *
 * @author jai
 * @since: v1.0
 */
public class ConvertiblePair {

	  /**
     * 数据源类型
     */
    private Class<?> sourceType;

    /**
     * 能够转成的数据的类型
     */
    private Class<?> targetType;

    public ConvertiblePair(Class<?> sourceType, Class<?> targetType) {
       this.sourceType = sourceType;
       this.targetType = targetType;
    }

	/**
	 * 是否匹配
	 * 
	 * @param sourceType
	 * @param targetType
	 * @return
	 */
	public boolean matches(Class<?> sourceType, Class<?> targetType) {
		if(sourceType == null || targetType == null){
			return false;
		}
		
		return this.sourceType.equals(sourceType) && this.targetType.equals(targetType);
	}
    
    /**
     * @return the sourceType
     */
    public Class<?> getSourceType() {
        return sourceType;
    }

    /**
     * @return the targetType
     */
    public Class<?> getTargetType() {
        return targetType;
    }
    
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((sourceType == null) ? 0 : sourceType.hashCode());
		result = prime * result
				+ ((targetType == null) ? 0 : targetType.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ConvertiblePair other = (ConvertiblePair) obj;
		return sourceType.equals(other.sourceType) && targetType.equals(other.targetType);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("类型转换 [sourceType=");
		builder.append(sourceType);
		builder.append(" --> targetType=");
		builder.append(targetType);
		builder.append("]");
		return builder.toString();
	}
}
